// TestOpttView.cpp : implementation file
//

#include "stdafx.h"
#include "GStation.h"
#include "TestOpttView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestOpttView

IMPLEMENT_DYNCREATE(CTestOpttView, CFormView)

CTestOpttView::CTestOpttView()
	: CFormView(CTestOpttView::IDD)
{
	//{{AFX_DATA_INIT(CTestOpttView)
	m_optt_v = _T("");
	//}}AFX_DATA_INIT
}

CTestOpttView::~CTestOpttView()
{
}

void CTestOpttView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestOpttView)
	DDX_Text(pDX, IDC_EDIT1, m_optt_v);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestOpttView, CFormView)
	//{{AFX_MSG_MAP(CTestOpttView)
	ON_BN_CLICKED(IDC_StartOpttTest, OnStartOpttTest)
	ON_BN_CLICKED(IDC_StopOpttTest, OnStopOpttTest)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestOpttView diagnostics

#ifdef _DEBUG
void CTestOpttView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTestOpttView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestOpttView message handlers

CGStationDoc * CTestOpttView::GetDocument()
{
	return (CGStationDoc * )m_pDocument;
}

void CTestOpttView::OnStartOpttTest() 
{
	// TODO: Add your control notification handler code here
	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TOT_OPTTRACETEST_START;
	while(doc->cln.OnSendData(buf,2)==false)
	{

	}
	free(buf);
}

void CTestOpttView::OnStopOpttTest() 
{
	// TODO: Add your control notification handler code here
	unsigned char * buf;
	buf = (unsigned char *)malloc(2);
	INSHEAD * head = (INSHEAD *)buf;
	*head  = TOT_OPTTRACETEST_STOP;
	while(doc->cln.OnSendData(buf,2)==false)
	{

	}
	free(buf);
}

void CTestOpttView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{

	if(doc->msg_OPTTRACETestData_tag == true)
	{
		doc->msg_OPTTRACETestData_tag = false;
		CString s;
		char c1 = '\r';
		char c2 = '\n';
		s.Format("OPTState %d %c%c",doc->msg_OPTTRACETestData.OPTState,c1,c2);
		m_optt_v = s;
		s.Format("N_Pos %f %c%c",doc->msg_OPTTRACETestData.N_Pos,c1,c2);
		m_optt_v += s;
		s.Format("E_Pos %f %c%c",doc->msg_OPTTRACETestData.E_Pos,c1,c2);
		m_optt_v += s;
		s.Format("D_Pos %f %c%c",doc->msg_OPTTRACETestData.D_Pos,c1,c2);
		m_optt_v += s;
		s.Format("N_Speed %f %c%c",doc->msg_OPTTRACETestData.p,c1,c2);
		m_optt_v += s;
		s.Format("E_Speed %f %c%c",doc->msg_OPTTRACETestData.q,c1,c2);
		m_optt_v += s;
		s.Format("D_Speed %f %c%c",doc->msg_OPTTRACETestData.r,c1,c2);
		m_optt_v += s;
		s.Format("N_Acc %f %c%c",doc->msg_OPTTRACETestData.N_Acc,c1,c2);
		m_optt_v += s;
		s.Format("E_Acc %f %c%c",doc->msg_OPTTRACETestData.E_Acc,c1,c2);
		m_optt_v += s;
		s.Format("D_Acc %f %c%c",doc->msg_OPTTRACETestData.D_Acc,c1,c2);
		m_optt_v += s;
		s.Format("phi %f %c%c",doc->msg_OPTTRACETestData.phi,c1,c2);
		m_optt_v += s;
		s.Format("theta %f %c%c",doc->msg_OPTTRACETestData.theta,c1,c2);
		m_optt_v += s;
		s.Format("psi %f %c%c",doc->msg_OPTTRACETestData.psi,c1,c2);
		m_optt_v += s;
		s.Format("phi_Acc %f %c%c",doc->msg_OPTTRACETestData.phi_Acc,c1,c2);
		m_optt_v += s;
		s.Format("theta_Acc %f %c%c",doc->msg_OPTTRACETestData.theta_Acc,c1,c2);
		m_optt_v += s;
		s.Format("psi_Acc %f %c%c",doc->msg_OPTTRACETestData.psi_Acc,c1,c2);
		m_optt_v += s;
	}
	UpdateData(false);	
	
}
